$(document).ready(function(){
    var schoolDom = $('#schoolId'),
        pathName = window.location.pathname.split('/'),
        target  = pathName[schoolDom.length > 0 ? pathName.length - 1 : pathName.length - 2],
        source  = {url: baseUrl + 'Stats/getSchoolChart', params: {target: target}},
        config  = {showLegends: false, showZoom: false, seriesFontSize: 15},
        colors  = {
            'fix': ['#59ADF3'],
            'brush': ['#AF89D6'],
            'practice': ['#FF999A'],
            'read': ['#FFCC67'],
            'duration': ['#86D560']
        },
        chart = (new xhChart).bar('chart', source, config);
    if(schoolDom.length > 0){
        schoolDom.select2({
            placeholder: '选择学校',
            allowClear: true
        });
        $('#bt_view').click(function(){
            source.params.startDate = $('#startDate').val();
            source.params.endDate = $('#endDate').val();
            source.params.schoolId = schoolDom.val();
            if(!source.params.startDate || !source.params.endDate){
                window.top.xhTop.showMessage({
                    title: '时间段不能为空！',
                    type: 'error'
                });
                return false;
            }
            (new xhChart).bar(chart, source, config);
        });

        //如为布置图表且单个学校展示时，点击展开教师布置详情
        if(target == 'fix'){
            chart.on('click', function(info){
                if(!source.params.schoolId) return false;
                var src = baseUrl + 'Stats/schoolSingleFixInfo?schoolId=' + source.params.schoolId + '&appName=' + info.name;
                if(source.params.startDate && source.params.endDate){
                    src += '&startDate=' + source.params.startDate + '&endDate=' + source.params.endDate;
                }
                window.top.xhTop.showModal({
                    title: schoolDom.find("option:selected").text(),
                    content: '<iframe frameborder="0" style="width: 100%;height: 400px;" src="' +src + '"></iframe>'
                });
            });
        }
    }
    else{
        config.xFontSize = 10;
        config.showSeriesInfo = false;
        config.color = colors[target];
    }

});